<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.Company"%>
<%@page import="db.CompanyDAO"%>
<%@page import="db.Place"%>
<%@page import="db.PlaceDAO"%>
<%@ include file="/jsp/common/utility/logined.jsp" %>

<%
	request.setCharacterEncoding("utf-8");
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	CompanyDAO companyDAO = (CompanyDAO)ctx.getBean("CompanyDAO");
	PlaceDAO placeDAO = (PlaceDAO)ctx.getBean("PlaceDAO");
	
	
	int tid = (Integer)session.getAttribute("tid");
	
	String name = request.getParameter("cname");
	String type = request.getParameter("type");
	request.setAttribute("type",type);
	String message = "";
	
	
	if(type=="2" || "2".equals(type)){
		if(name==null || "".equals(name)){
				message = "添加库位信息失败，库位名称不能为空。";
				request.setAttribute("message",message);
				request.setAttribute("suess",false);
				pageContext.forward("/vm/place/add_coninfo.vm");
				return;
		}
		
		List md = placeDAO.findByName(name);
		if(md != null && md.size() > 0){
			message = "添加库位信息失败，库位名称已经存在。";
			request.setAttribute("suess",false);
			request.setAttribute("message",message);
			pageContext.forward("/vm/place/add_coninfo.vm");
			return;
		}
		
		
		
		
		
		Place co = new Place();
		co.setName(name);
		placeDAO.save(co);
		message = "恭喜您！添加库位信息成功!";
		request.setAttribute("message",message);
		request.setAttribute("suess",true);
		pageContext.forward("/vm/place/add_coninfo.vm");
	}else{
		pageContext.forward("/vm/place/add_coninfo.vm");
	}
	
%>
